package com.shilei.iterator.v1;

/**
 * @description: 构建一个容器 ，可以添加对象  数组
 * @author: 81271
 * @date: 2020-04-19 19:52
 */
public class Main {
    public static void main(String[] args) {
        ArrayList_ arrayList_ = new ArrayList_();
        for (int i = 0; i < 15; i++) {
            arrayList_.add("i" + i);
        }
        System.out.println(arrayList_.size());
    }
}

class ArrayList_ {
    private Object[] objects = new Object[10];
    //objects中下一个空位在哪， 或者说数组中存在着多少个元素
    private int index = 0;

    public void add(Object o) {
        if (index == objects.length) {
            Object[] newObjects = new Object[objects.length * 2];
            System.arraycopy(objects, 0, newObjects, 0, objects.length);
            objects = newObjects;
        }
        objects[index] = 0;
        index ++;
    }

    public int size() {
        return index;
    }
}

